#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
数据结构模块

包含所有数据类和结构定义，用于存储分析过程中的各种数据
"""

from dataclasses import dataclass, field
from datetime import datetime
from typing import List, Any, Optional, Dict
from .enums import QueryType, ProblemType, DiagnosisStrategy
from .sql_client import SQLResponse


@dataclass
class DataQualityMetrics:
    """数据质量评估指标"""
    overall_score: float = 0.0
    issues: List[str] = field(default_factory=list)


@dataclass
class QueryResult:
    """查询结果数据结构"""
    query_type: QueryType
    query_text: str
    response: SQLResponse
    data_quality: DataQualityMetrics
    execution_time: float
    round_number: int
    success: bool
    error_message: Optional[str] = None


@dataclass
class AnalysisContext:
    """分析上下文"""
    user_input: str
    problem_type: ProblemType
    diagnosis_strategy: DiagnosisStrategy
    device_ids: List[str]
    current_round: int
    max_rounds: int
    previous_results: List[QueryResult] = field(default_factory=list)
    insights: List[str] = field(default_factory=list)
    expected_insights: List[str] = field(default_factory=list)
    needs_continuation: bool = True
    start_time: Optional[datetime] = None


@dataclass
class DiagnosisResult:
    """诊断结果"""
    status: str
    analysis_rounds: int
    total_queries: int
    diagnosis_path: List[str]
    findings: Dict[str, Any]
    recommendations: List[str]
    data_quality_summary: Dict[str, float]
    execution_time: float
    llm_conclusion: str